#!/usr/bin/perl
#creating.cgi

require './mirrorman-lib.pl';
&ReadParse();
&error_setup($text{'error_mesg'});
$modname=$in{'modname'};
$modpath=$in{'modpath'};
$modcomment=$in{'modcomment'};
$mirrorline=$modname.":".$modpath.":"."R".":".$modcomment;
open(FH, "/sysvol/etc/mirrortab");
@mirrortab=<FH>;
close(FH);

#check input inofmation for creating a new mirror mod
#$mark=&check_modname($modname);
$mark=1;
if(($modname=~ /[^a-zA-Z0-9]/) || ($modname =~ /^\d+(.*)/) || ($modname eq "end")){
   &error($text{'mesg_wrong_modname'});
}
foreach(@mirrortab){
   @tmp=split(/:/, $_);
   if($modname eq $tmp[0]){
       &error($text{'mesg_mod_alreadyexist'});
   }
}

if(!(-e $modpath)){
   &error($text{'mesg_path_notexist'});
}

if(($modpath !~ /^\//) || ($modpath !~ /\/$/)){
   &error($text{'mesg_path_error'});
}

if($mark==0){
   &redirect("error.cgi");
}else{
   &add_mirrortab($mirrorline, @mirrortab);
   if(!(-e "/sysvol/etc/rsyncd.conf")){
      system('cp /etc/rsyncd.conf.bak /sysvol/etc/rsyncd.conf');
   }
   &add_rsyncd_conf($modname, $modpath, $modcomment);
   &redirect("index.cgi"); 
}
